package com.xiaoliang.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * @author XIAOLIANG
 * @ClassName AddOrUpdate.java
 * @Description TODO
 * @createTime 2021年02月26日 11:30:00
 */
//@WebServlet("/product/addOrUpdate")
public class AddOrUpdate extends HttpServlet {

	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		String type = req.getParameter("type");
		HttpSession session = req.getSession();

		if ("add".equals(type)){                   //携带type=add 参数 表示添加的请求 需要清空session 中的product
			session.removeAttribute("product");
			session.setAttribute("type",2);

		}else {
			session.setAttribute("type",1);
		}

		resp.sendRedirect(req.getContextPath()+"/product/addOrUpdate.jsp");
	}
}
